define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'task/order/index',
                    add_url: 'task/order/add',
                    edit_url: 'task/order/edit',
                    del_url: 'task/order/del',
                    multi_url: 'task/order/multi',
                    table: 'shop_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_sno', title: __('Order_sno')},
                        {field: 'task_sno', title: __('Task_sno')},
                        {field: 't.task_type', title: __('Task_type'),searchList: {
                            "1":__('精刷单'),
                            "2":__('隔日单'),
                            "3":__('流量单')
                        },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {field: 'o.shop_name', title: __('Shop_name'),operate:"LIKE"},
                        {field: 'real_money', title: __('Deal_price'),operate:false},
                        {field: 'insert_price', title: __('Insert_price'),operate:false},
                        {field: 'order_goldbean_amount', title: __('Commission'),operate:false},
                        {field: 'paike_name', title: __('Paike_name'),operate:false},
                        {field: 'tao_bao_no', title: __('Tao_bao_no')},
                        {field: 'tao_bao_order_no', title:__('Tao_bao_order_no')},
                        {field: 'o.create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'o.status', title: __('订单状态'),searchList: {
                                "0":__('已拍下'),
                                "1":__('未审核'),
                                "2":__('已审核'),
                                "3":__('已上传'),
                                "4":__('已复查'),
                                "5":__('已付款'),
                                "6":__('已下单'),
                                "7":__('待发货'),
                                "8":__('待好评'),
                                "9":__('已发货'),
                                "10":__('已好评'),
                                "11":__('待追评'),
                                "12":__('已追评'),
                                "13":__('已完成'),
                        },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                if(value=="" || value==null){
                                    value = value;
                                }else{
                                    value = value.toString();
                                }
                                if(value==0){
                                    value = "0";
                                }
                                var index = keys.indexOf(value);
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {
                            field: 'is_cancel',
                            title: __('是否取消'),
                            searchList: {"1":__('否'),"2":__('是')},
                            formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {
                            field: 'order_state',
                            title: __('核对状态'),
                            searchList: {"0":__('正常'),"1":__('已撤销'),"2":__('已回收')},
                            formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter:function(value,row,index) {

                                var table = this.table;
                                // 操作配置
                                var options = table ? table.bootstrapTable('getOptions') : {};
                                // 默认按钮组
                                var buttons = $.extend([], this.buttons || []);
                                buttons.push(
                                    {
                                        name: 'btn_2',
                                        text: "详情",
                                        extend: 'data-toggle="tooltip" data-name="btn_2" data-title="详情"',
                                        classname: 'btn btn-xs btn-success btn-magic btn-editone '
                                    });
                                return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
                            }
                        }
                        // {field: 'author_status', title: __('Author_status'), searchList: {"0":__('未审核'),"1":__('正常'),"2":__('被驳回')},formatter:function(value,row,index){
                        //         var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                        //         var index = keys.indexOf(value.toString());
                        //         value = value === null ? '' : value.toString();
                        //         var display = index > -1 ? this.searchList[value] : null;
                        //         var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                        //         if (!display) {
                        //             display = __(value.charAt(0).toUpperCase() + value.slice(1));
                        //         }
                        //         var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';
                        //
                        //         return html;
                        //     }},

                    ]
                ]
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            $(function(){

                    require(['img_css/easy-loading','img_css/hammer.min','img_css/jquery.mousewheel.min','img_css/zoom-marker'],function(){
                        // $('#zoom-marker-img').zoomMarker({
                        //     src: $('#zoom-marker-img').data("url"),
                        //     rate: 0.2,
                        //     width: 100,
                        //     max: 1000,
                        //     markers:[
                        //         //{src:"img/marker.svg", x:500, y:500}
                        //     ]
                        // });
                        $("img").each(function(){
                            console.log($(this).data("url"));
                            if($(this).data("url")!=undefined && $(this).data("url")!="") {
                                $(this).zoomMarker({
                                    src: $(this).data("url"),
                                    rate: 0.1,
                                    min: 100,
                                    width: 100,
                                    max: 3000,
                                    markers: [
                                        //{src:"img/marker.svg", x:500, y:500}
                                    ],
                                });
                            }
                        });

            }); })
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});